package com.company.剑指offer每日刷题.普通版;

/**
 * 剑指 Offer 05. 替换空格
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * 限制：
 *
 * 0 <= s 的长度 <= 10000
 * */
public class ReplaceSpace {
    public String replaceSpace(String s) {
        StringBuilder builder = new StringBuilder ();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' '){
                builder.append("%20");
                continue;
            }
            builder.append(s.charAt(i));
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        ReplaceSpace obj = new ReplaceSpace();
        String we_are_happy = obj.replaceSpace("We are happy");
        System.out.println(we_are_happy);

    }
}
